
<div data-role="page">
<div data-role="navbar">
	<ul>
		<li><a href="<?php echo URL?>ratings.php" class="ui-btn-active ui-state-persist">Rating</a></li>
		<li><a href="<?php echo URL?>matchs.php">Matchs</a></li>
		<li><a href="<?php echo URL?>players.php">Players</a></li>
                
	</ul>
</div><!-- /navbar -->

        <a href="#AddMatchForm" data-rel="popup" data-role="button">Add Match</a>
        <a href="#AddPlayerForm" data-rel="popup" data-role="button">Add Player</a>
        <a href="<?php echo URL . "matchs" ?>" data-rel="popup" data-role="button" data-ajax="false">View results</a>
        
        <div data-role="popup" id="AddMatchForm">
            <div>
            <form action="<?php echo URL ?>login/addMatch" method="get" data-ajax="false">
                <div class="ui-grid-a">
                    <div class="ui-block-a">
                        <h2>
                            Team A
                        </h2>
                    </div>
                    <div class="ui-block-b">
                        <h2>
                            Team B
                        </h2>
                    </div>
                    <div class="ui-block-a">
                        <div data-role="fieldcontain">
                            <label for="selectTeamAPlayer1">
                                Player 1
                            </label>
                             <select name="selectTeamAPlayer1" data-mini="true">
                            <?php 
                            $matchdata = $this->model->GetUserNames();
                            while($userdata = $matchdata->fetch())
                            {
                              $name = $userdata['username'];
                              $memberId = $userdata['memberId'];
                              echo '      <option value="'.$memberId.'">'.PHP_EOL;
                              echo '          '.$name.PHP_EOL;
                              echo '      </option>'.PHP_EOL;
                            }
                            ?>                                   
                            </select>
                        </div>
                    </div>
                    <div class="ui-block-b">
                        <div data-role="fieldcontain">
                            <label for="selectTeamBPlayer1">
                                Player 1
                            </label>
                             <select name="selectTeamBPlayer1" data-mini="true">
                            <?php 
                            $matchdata = $this->model->GetUserNames();
                            while($userdata = $matchdata->fetch())
                            {
                              $name = $userdata['username'];
                              $memberId = $userdata['memberId'];
                              echo '      <option value="'.$memberId.'">'.PHP_EOL;
                              echo '          '.$name.PHP_EOL;
                              echo '      </option>'.PHP_EOL;
                            }
                            ?>                                   
                            </select>

                        </div>
                    </div>
                    <div class="ui-block-a">
                        <div data-role="fieldcontain">
                            <label for="selectTeamAPlayer2">
                                Player 2
                            </label>
                             <select name="selectTeamAPlayer2" data-mini="true">
                            <?php 
                            $matchdata = $this->model->GetUserNames();
                            while($userdata = $matchdata->fetch())
                            {
                              $name = $userdata['username'];
                              $memberId = $userdata['memberId'];
                              echo '      <option value="'.$memberId.'">'.PHP_EOL;
                              echo '          '.$name.PHP_EOL;
                              echo '      </option>'.PHP_EOL;
                            }
                            ?>                                   
                            </select>
                        </div>
                    </div>
                    <div class="ui-block-b">
                        <div data-role="fieldcontain">
                            <label for="selectTeamBPlayer2">
                                Player 2
                            </label>
                             <select name="selectTeamBPlayer2" data-mini="true">
                            <?php 
                            $matchdata = $this->model->GetUserNames();
                            while($userdata = $matchdata->fetch())
                            {
                              $name = $userdata['username'];
                              $memberId = $userdata['memberId'];
                              echo '      <option value="'.$memberId.'">'.PHP_EOL;
                              echo '          '.$name.PHP_EOL;
                              echo '      </option>'.PHP_EOL;
                            }
                            ?>                                   
                            </select>
                        </div>
                    </div>
                    <div class="ui-block-a">
                        <div data-role="fieldcontain">
                            <label for="pointsTeamA">
                                Score
                            </label>
                            <select name="pointsTeamA" data-mini="true">
                                <?php
                                for($score = 0; $score <= 10; $score+= 1)
                                {
                                  echo '<option value="'.$score.'">'.$score.' </option>'.PHP_EOL;
                                }
                                ?>
                            </select>
                        </div>
                    </div>
                    <div class="ui-block-b">
                        <div data-role="fieldcontain">
                            <label for="pointsTeamB">
                                Score
                            </label>
                            <select name="pointsTeamB" data-mini="true">
                                <?php
                                for($score = 0; $score <= 10; $score+= 1)
                                {
                                  echo '<option value="'.$score.'">'.$score.' </option>'.PHP_EOL;
                                }
                                ?>
                            </select>
                        </div>
                    </div>
                </div>
                <button type="submit" data-theme="b" name="submit" value="submit-value">Add</button>              
            </form>
            </div>
        </div> 

       <div data-role="popup" id="AddPlayerForm">
            <div>
            <form action="<?php echo URL ?>login/addPlayer" method="get" data-ajax="false">
               <label for="username">Username</label>
               <input type="text" name="username" id="username" value=""  />   
             <button type="submit" data-theme="b" name="submit" value="submit-value">Add</button>    
            </form>
            </div>
       </div>
        
        <h2>Scores</h2>
        <table id="scores" >
            <tr class="HeadLine"><td>User</td><td>Score</td></tr>
            <?php
            $ScoreData = $this->model->PrintHighScoreTable();

            $rowcount = 0;

            while ($matchdata = $ScoreData->fetch()) {

                $username = $matchdata['username'];
                $score = $matchdata['rating'];
                $rowcount += 1;
                if ($rowcount % 2 == 1)
                    echo"<tr class=\"alt\">\n";
                else
                    echo"<tr>\n";
                echo"<td>$username</td>\n";
                echo"<td>$score</td>\n";
                echo"</tr>\n";
            }
            ?>
        </table>

 